﻿@model TrialManagmentTool.Models.ReportViewModel
@{
    ViewBag.Title = @Model.title;
    Layout = "~/Views/Shared/Layout.Mobile.cshtml";
}

<style>
    a {
        color: #ffffff;
    }
</style>
<div class="page-group">
    <div class="page page-current">
        <div class="headClass">&nbsp;&nbsp;@Model.trialDetail.Product &nbsp;&nbsp;@Model.trialDetail.Crop &nbsp;&nbsp;@Model.trialDetail.Province</div>
        <div class="content">
            <div class="list-block">
                <div class="list-block list-block-noborder" style="margin-top:2rem">
                    <ul>
                        <!-- Text inputs -->
                        <li class="displaylistblock" id="maindata1">
                            <div class="item-content">
                                <div class="item-media"><i class="icon icon-city"></i></div>
                                <div class="item-inner item-inner-noborder">
                                    <div class="item-title label" style="width:35%">@Model.dataList[0].ChineseDesc</div>
                                    <div class="item-input">
                                        <input type="text" id="cityname" value='@Model.trialDetail.TrialSite.Address' readonly />
                                        @*<input type="text">*@
                                    </div>
                                </div>
                            </div>
                        </li>
                        <li class="displaylistblock" id="maindata2">
                            <div class="item-content">
                                <div class="item-media"><i class="icon icon-coorpate"></i></div>
                                <div class="item-inner item-inner-noborder">
                                    <div class="item-title label" style="width:35%">@Model.dataList[1].ChineseDesc</div>
                                    <div class="item-input ">
                                        <input type="text" id="coorpate" value='@Model.trialDetail.TrialSite.Partner' readonly>
                                    </div>
                                </div>
                            </div>
                        </li>
                        <li class="displaylistblock" id="maindata3">
                            <div class="item-content">
                                <div class="item-media"><i class="icon icon-pinzhong"></i></div>
                                <div class="item-inner item-inner-noborder">
                                    <div class="item-title label" style="width:35%">@Model.dataList[2].ChineseDesc</div>
                                    <div class="item-input">
                                        <input type="text" id="zacao" value='@Model.trialDetail.TrialSite.CropCategory' readonly>
                                    </div>
                                </div>
                            </div>
                        </li>

                        <li class="displaylistblock" id="maindata4">
                            <div class="item-content">
                                <div class="item-media"><i class="icon icon-zaipei"></i></div>
                                <div class="item-inner item-inner-noborder">
                                    <div class="item-title label" style="width:35%">@Model.dataList[3].ChineseDesc</div>
                                    <div class="item-input">
                                        <input type="text" id="pinzhong" value='@Model.trialDetail.TrialSite.SeedMode' readonly>
                                    </div>
                                </div>
                            </div>
                        </li>

                        <li class="displaylistblock" id="maindata5">
                            <div class="item-content">
                                <div class="item-media"><i class="icon icon-zacao"></i></div>
                                <div class="item-inner item-inner-noborder">
                                    <div class="item-title label" style="width:35%">@Model.dataList[4].ChineseDesc</div>
                                    <div class="item-input">
                                        <input type="text" id="season" value='@Model.trialDetail.TrialSite.Object' readonly>
                                    </div>
                                </div>
                            </div>
                        </li>
                        <li class="displaylistblock" id="maindata6">
                            <div class="item-content">
                                <div class="item-media"><i class="icon icon-fengbi"></i></div>
                                <div class="item-inner item-inner-noborder">
                                    <div class="item-title label" style="width:35%">@Model.dataList[5].ChineseDesc</div>
                                    <div class="item-input">
                                        <input type="text" id="fengbi" readonly>
                                    </div>
                                </div>
                            </div>
                        </li>
                        <li class="displaylistblock" id="maindata7">
                            <div class="item-content">
                                <div class="item-media"><i class="icon icon-season"></i></div>
                                <div class="item-inner item-inner-noborder">
                                    <div class="item-title label" style="width:35%">@Model.dataList[6].ChineseDesc</div>
                                    <div class="item-input">
                                        <input type="text" id="zaipei" value='@Model.trialDetail.TrialSite.SubCropCategory' readonly>
                                    </div>
                                </div>
                            </div>
                        </li>

                    </ul>
                    <div class="list-block" style="width:98%;margin-bottom:1px;margin-top:0px">
                        <ul>
                            @for (int i = 0; i < Model.trialDetail.Reports.Count(); i++)
                            {
                                <li class="item-content">
                                    <div class="item-media"><i class="icon icon-f7"></i></div>
                                    <div class="item-inner" onclick="ReportDetail(@Model.trialDetail.Reports[i].ID)">
                                        <div class="item-title">@Model.trialDetail.Reports[i].Name</div>
                                        <div class="item-after"><span class="icon icon-right"></span></div>
                                    </div>
                                </li>
                            }
                        </ul>
                    </div>
                    @if (Model.trialDetail.Status == 0 || Model.trialDetail.Status == 1)
                    {
                        <div>
                            <img style="height:14px;margin:8px;float:left;margin-right:5px" src="@TrialManagementTool.Helper.UrlHelper.alterContent("Images/Group.png")" />
                            <p><a href="#" class="prompt-ok-cancel" style="font-size:20px">添加处理</a></p>
                        </div>
                    }
                    <div>
                        <img style="height:18px;margin:6px;float:left;margin-right:5px" src="@TrialManagementTool.Helper.UrlHelper.alterContent("Images/summary.png")" />
                        <p><a href="#" style="font-size:20px" onclick="ValidatStaus()">总结</a></p>
                    </div>
                    <a href="#" style="width:80%;margin:20px auto 30px auto" class="button button-big button-fill button-success" onclick="location.href='@TrialManagementTool.Helper.UrlHelper.alterContent("TrialMobile/Shifandian?id="+Model.trialDetail.TrialID)'">示范点列表</a>
                </div>
            </div>
        </div>
        <div style="position:absolute;right:0;top:100px;z-index:2001">
            <a class="filterArea" onclick="loadPage()"> <img src="@TrialManagementTool.Helper.UrlHelper.alterContent("Images/fangan.png")" class="fangan" />  </a>
        </div>
    </div>
    <div class="page" id="purpose">
        <header class="bar bar-nav">
            <a class="button button-link button-nav pull-left back">
                <span class="icon icon-left"></span>
                返回
            </a>
            <h1 class='title'>示例方案</h1>
        </header>
        <div class="content" style="width:90%">

            @{var data = new ViewDataDictionary();

            data.Add("TrialGuideID", @Model.trialDetail.TrialGuideID);
            Html.RenderPartial("Purpose", null, data); }
        </div>
    </div>
</div>
<script>
    var allowsubmit = true;
    $(document).on('click', '.prompt-ok-cancel', function () {
        $.prompt('请填写处理名称',
          function (value) {
              if (value != "") {
                  if (value.indexOf("<") > 0 || value.indexOf(">") > 0 || value.indexOf("/") > 0 || value.indexOf("/") > 0) {
                      $.toast("处理名称不能含有特殊字符");
                  } else {
                      if (allowsubmit == true) {
                          allowsubmit = false;
                          $.ajax({
                              url: fixUrl("api/Trial/CreateNewProcess"),
                              type: "post",
                              data: { name: value, id: '@Model.trialDetail.TrialSiteID' },
                              success: function (data) {
                                  if (data > 0) {
                                      location.href = fixUrl("TrialMobile/ProcessManagement?id=" + data);
                                  } else {
                                      $.alert('创建失败');
                                  }
                              },
                              error: function (data) {
                                  allowsubmit = true;
                                  if (data.status == "401") {
                                      $.alert('登录超时');
                                  } else {
                                      $.alert('保存失败,请重试');
                                  }
                              }
                          })
                      }
                  }
              } else {
                  $.toast("处理名称不能为空");
              }
          },
          function (value) {

          }
        );
    });
    function loadPage() {
        $.router.load("#purpose");
        init();
    }
    function ReportDetail(id) {
        location.href = fixUrl("TrialMobile/ProcessManagement?id=" + id);
    }

    function ValidatStaus() {
        $.ajax({
            url: fixUrl("api/Trial/CheckTrialMandaryFields"),
            data: { id: '@Model.trialDetail.TrialSiteID' },
            success: function (data) {
                if (data.length > 0) {
                    var err = "";
                    $.each(data, function (index, value) {
                        if (index < 8) {
                            err += value.ReportName + ":" + value.FieldName + "未填写</br>";
                        }
                    })
                    $.alert(err);
                } else {
                    location.href = fixUrl("TrialMobile/FinalReport?id=" + '@Model.trialDetail.TrialSiteID');
                }
            },
            error: function (data) {
                if (data.status == "401") {
                    $.alert('登录超时');
                } else {
                    $.alert('验证失败');
                }
            }
        })
    }

</script>
@for (int i = 0; i < Model.dataList.Count(); i++)
{
    if (Model.dataList[i].display == false)
    {
        <script>
            $("#maindata" + (@i+1)).css("display", 'none');
        </script>
    }
}

@if (Model.trialDetail.TrialSite.IsClosed.HasValue && Model.trialDetail.TrialSite.IsClosed.Value == true)
{
    <script>
        $("#fengbi").val("是");
    </script>
}
else
{
    <script>
        $("#fengbi").val("否");
    </script>
}
